package biz

import (
	"cyiris/app/demo/models"
	"cyiris/common/utils"
	"cyiris/core/core"
	"encoding/json"
	"time"
)

type TestBiz struct {
}

func NewTestBiz() *TestBiz {
	return &TestBiz{}
}

func (biz *TestBiz) Handle(name, email string) int64 {
	db, err := core.GetMysqlDb("test")

	if nil != err {
		return 0
	}

	user := &models.TUser{
		Name:       name,
		Email:      email,
		CreateTime: time.Now().Unix(),
		UpdateTime: time.Now().Unix(),
	}

	data, _ := json.Marshal(user)
	utils.Send2Demo("/demo/test/pushmsg", data)

	err = user.Create(db)

	if nil != err {
		return 0
	}

	return 1
}
